//
//  EXResponseMessage.m
//  Edaox
//
//  Created by cao pan on 7/10/14.
//  Copyright (c) 2014 edaox. All rights reserved.
//

#import "EXResponseMessage.h"
#import "JSONKit.h"
#import "AFHTTPClient.h"

@implementation EXResponseMessage

NSString  * const kResponseStatus = @"result";
NSString  * const kResponseMessage = @"message";
NSString  * const kResponseCode = @"resultCode";
NSString  * const kResponseResult = @"results";
NSString  * const kResponseCollection = @"collection1";

NSInteger const kResponseSuccessCode = 0;


@synthesize     responseBody    = _responseBody;
@synthesize     isSuccessed     = _isSuccessed;
@synthesize     responseMessage = _responseMessage;
@synthesize     responseCode    = _responseCode;
@synthesize     responseObj     = _responseObj;
@synthesize     collectionArr   = _collectionArr;

- (void)parserResponseBody:(id)responseBody
{
    
    NSString     *responseString = [[NSString alloc] initWithData:responseBody encoding:NSUTF8StringEncoding];
    _responseObj = responseString;
    
    NSDictionary * responseDict = [responseString  objectFromJSONString];
    NSDictionary * resultDict   = [responseDict objectForKey:kResponseResult];
    
    _responseBody = resultDict;
    _collectionArr = [resultDict objectForKey:kResponseCollection];
    
#if 0
    
    NSDictionary *responseDict = [responseString objectFromJSONString];
    NSDictionary *responseStatusDict = [responseDict objectForKey:kResponseStatus];
    
    _responseBody = responseStatusDict;
    
    _responseCode  = [responseStatusDict objectForKey:kResponseCode];
    _responseMessage = [responseStatusDict objectForKey:kResponseMessage];
    LOG(@"response is %@",responseDict);
    
    if (_responseCode.length == 0 && _responseMessage.length == 0) {
        _isSuccessed = YES;
        _responseBody = responseDict;
    }else{
        _isSuccessed = NO;
        dispatch_async(dispatch_get_main_queue(), ^{
            Alert(/*_responseCode*/@"提示", _responseMessage);
        });
    }
#endif
    
}


@end
